libxc: convert xc_version over to hypercall buffers
authorIan Campbell <ian.campbell@citrix.com>
Fri, 22 Oct 2010 14:14:51 +0000 (15:14 +0100)
committerIan Campbell <ian.campbell@citrix.com>
Fri, 22 Oct 2010 14:14:51 +0000 (15:14 +0100)
Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Signed-off-by: Ian Jackson <ian.jackson.citrix.com>
tools/libxc/xc_private.c
tools/libxc/xc_private.h

index 5f54d62b4549cdd51b16b678ff7cdcba657ac5ad..2b862a5814a1d49646a7c3182a2f61a739727afa 100644 (file)
@@ -567,42 +567,46 @@ int xc_sysctl(xc_interface *xch, struct xen_sysctl *sysctl)
 
 int xc_version(xc_interface *xch, int cmd, void *arg)
 {
-    int rc, argsize = 0;
+    DECLARE_HYPERCALL_BOUNCE(arg, 0, XC_HYPERCALL_BUFFER_BOUNCE_OUT); /* Size unknown until cmd decoded */
+    size_t sz = 0;
+    int rc;
 
     switch ( cmd )
     {
     case XENVER_extraversion:
-        argsize = sizeof(xen_extraversion_t);
+        sz = sizeof(xen_extraversion_t);
         break;
     case XENVER_compile_info:
-        argsize = sizeof(xen_compile_info_t);
+        sz = sizeof(xen_compile_info_t);
         break;
     case XENVER_capabilities:
-        argsize = sizeof(xen_capabilities_info_t);
+        sz = sizeof(xen_capabilities_info_t);
         break;
     case XENVER_changeset:
-        argsize = sizeof(xen_changeset_info_t);
+        sz = sizeof(xen_changeset_info_t);
         break;
     case XENVER_platform_parameters:
-        argsize = sizeof(xen_platform_parameters_t);
+        sz = sizeof(xen_platform_parameters_t);
         break;
     }
 
-    if ( (argsize != 0) && (lock_pages(xch, arg, argsize) != 0) )
+    HYPERCALL_BOUNCE_SET_SIZE(arg, sz);
+
+    if ( (sz != 0) && xc_hypercall_bounce_pre(xch, arg) )
     {
-        PERROR("Could not lock memory for version hypercall");
+        PERROR("Could not bounce buffer for version hypercall");
         return -ENOMEM;
     }
 
 #ifdef VALGRIND
-    if (argsize != 0)
-        memset(arg, 0, argsize);
+    if (sz != 0)
+        memset(hypercall_bounce_get(bounce), 0, sz);
 #endif
 
-    rc = do_xen_version(xch, cmd, arg);
+    rc = do_xen_version(xch, cmd, HYPERCALL_BUFFER(arg));
 
-    if ( argsize != 0 )
-        unlock_pages(xch, arg, argsize);
+    if ( sz != 0 )
+        xc_hypercall_bounce_post(xch, arg);
 
     return rc;
 }
index 41e22f8c8a9e583e6c4266d0806f683b16c2c78c..a9394f76d434ae028718cc8a5a5eb57a7df9f0b1 100644 (file)
@@ -166,13 +166,14 @@ void xc__hypercall_bounce_post(xc_interface *xch, xc_hypercall_buffer_t *bounce)
 
 int do_xen_hypercall(xc_interface *xch, privcmd_hypercall_t *hypercall);
 
-static inline int do_xen_version(xc_interface *xch, int cmd, void *dest)
+static inline int do_xen_version(xc_interface *xch, int cmd, xc_hypercall_buffer_t *dest)
 {
     DECLARE_HYPERCALL;
+    DECLARE_HYPERCALL_BUFFER_ARGUMENT(dest);
 
     hypercall.op     = __HYPERVISOR_xen_version;
     hypercall.arg[0] = (unsigned long) cmd;
-    hypercall.arg[1] = (unsigned long) dest;
+    hypercall.arg[1] = HYPERCALL_BUFFER_AS_ARG(dest);
 
     return do_xen_hypercall(xch, &hypercall);
 }